<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\Centers\CentersUpdateRequest;
use App\Models\Centers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CentersController extends Controller
{
    public function show(Request $request) {


        if (Auth::id() == 1) {
            $centers = Centers::paginate(15);

        } else {
            $centers = Centers::where('user_id', Auth::id())->get();
        }

        return view('centers.show', compact('centers'));
    }

    public function edit(Centers $center) {
        return view('centers.edit', compact('center'));
    }

    public function update(CentersUpdateRequest $request, Centers $center) {

        $data = $request->validated();

        $center->update($data);

        return redirect(route('centers'));
    }
}
